<template>
	<view class="pages-service" :style="{background:pageColor}">
		<fixed>
			<search @input="toSearch" type="input" :padding="30" :radius="0" placeholder="请输入服务名称">
			</search>
		</fixed>

		<view class="ml-md mr-md" :class="[{'flex-warp':service_list_type===3}]">
			<view class="mt-md"
				:class="[{'fill-base pd-lg radius-16':service_list_type!==3 && service_list_type!==4},{'mr-md':service_list_type===3&&index%2==0}]"
				v-for="(item,index) in list.data" :key="index">
				<longbingbing-service-list-item :info="item"
					:o="{type:service_list_type}"></longbingbing-service-list-item>
			</view>
		</view>

		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1" :isCenter="true">
		</abnor>
		<view class="space-footer"></view>

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex"
	import longbingbingServiceListItem from "@/components/longbingbing-service-list-item.vue"
	export default {
		components: {
			longbingbingServiceListItem
		},
		data() {
			return {
				options: {},
				param: {
					page: 1,
				},
				list: {
					data: []
				},
				loading: true,
				lockTap: false,
			}
		},
		computed: mapState({
			realtime_location: state => state.config.configInfo.realtime_location,
			service_list_type: state => state.config.configInfo.service_list_type,
			technicianParam: state => state.technician.param
		}),
		onLoad(options) {
			let {
				title = 0,
					industry = 0
			} = options
			console.log(options, 'options')
			options.industry = industry
			this.options = options
			uni.setNavigationBarTitle({
				title
			})
			this.initIndex()
		},
		// #ifdef H5
		destroyed() {
			// #endif
			// #ifndef H5
			onUnload() {
					// #endif 
					this.updateUserItem({
						key: 'appShare',
						val: true
					})
				},
				onPullDownRefresh() {
					// #ifndef APP-PLUS
					uni.showNavigationBarLoading()
					// #endif
					this.initRefresh();
					uni.stopPullDownRefresh()
				},
				onReachBottom() {
					if (this.list.current_page >= this.list.last_page || this.loading) return;
					this.param.page = this.param.page + 1;
					this.loading = true;
					this.getList();
				},
				methods: {
					...mapMutations(['updateUserItem', 'updateOrderItem', 'updateTechnicianItem',
						'updateMapItem', 'updateShopstoreItem', 'updateDynamicItem'
					]),
					async initIndex(refresh = false) {
						await this.getList()
						this.$util.setNavigationBarColor({
							bg: this.primaryColor
						})
						// #ifdef H5
						if (!refresh) {
							this.$jweixin.hideOptionMenu()
						}
						// #endif
					},
					initRefresh() {
						this.param.page = 1
						this.initIndex(true)
					},
					toSearch(val) {
						this.param.page = 1
						this.param.title = val
						this.getList()
					},
					async getList() {
						let {
							list: oldList,
							param
						} = this
						let {
							id,
							industry = 0
						} = this.options
						if (industry * 1 > 0) {
							param.industry_id = id
						} else {
							param.cate_id = id
						}
						let {
							lat,
							lng
						} = this.location
						let {
							realtime_location
						} = this
						param = Object.assign({}, param, {
							lat,
							lng,
							sort: realtime_location ? 'type desc' : 'top desc'
						})

						let {
							city_id = 0
						} = this.technicianParam
						let {
							id: city_info_id = 0
						} = this.city_info
						city_id = city_id || city_info_id
						if (city_id) {
							param.city_id = city_id
						}
						let methodModel = realtime_location ? 'getCoachService' : 'serviceList'
						let newList = await this.$api.service[methodModel](param);
						if (this.param.page == 1) {
							this.list = newList
						} else {
							newList.data = oldList.data.concat(newList.data)
							this.list = newList
						}
						this.loading = false
						this.$util.hideAll()
					},
				}
		}
</script>


<style lang="scss">
</style>